
var class_num=location.search;
class_num=class_num.split('?')[1];
$('header .title').append(class_num);
$('#href_list').attr('href','details_stu.html?'+class_num);
$('#href_course').attr('href','details_course.html?'+class_num);
$('#homework').attr('href','homework.html?'+class_num);
$('#href_file').attr('href','details_file.html?'+class_num);
if (islogin()) {
    $.ajax({
        url:'../../requests/teacher/show_details_stu.php',
        async:false,
        type:'POST',
        data:{'class_num':class_num},
        success:function (data) {
            if (data.length == 0) {
                $('.stu_list ul').append("<li>该班级没有学生</li>");
            }
            else {
                for (var i = 0; i < data.length; i++) {
                    var dom = "<li>\n" +
                        "                        <label class=\"label-checkbox item-content\">\n" +
                        "                            <input type=\"checkbox\" name=\"select_num\" value='"+data[i].num+"'>\n" +
                        "                            <div class=\"item-media\"><i class=\"icon icon-form-checkbox\"></i></div>\n" +
                        "                            <div class=\"item-inner\">\n" +
                        "                                <div class=\"item-title-row\">\n" +
                        "                                    <div class=\"item-title\">"+data[i].name+"</div>\n" +
                        "                                </div>\n" +
                        "                                <div class=\"item-subtitle pull-right\">"+data[i].num+"</div>\n" +
                        "                            </div>\n" +
                        "                        </label>\n" +
                        "                    </li>";
                    $('.stu_list ul').append(dom);
                }
            }
        }
    });
    $('#op').click(function () {
        var button1=[
            {
                text:'添加',
                onClick:function () {
                    window.location.href='add_stu.html';
                }
            },
            {
                text:'删除',
                onClick:function () {
                    $$.confirm('确认删除?',
                        function () {
                            var stu_nums=new Array();
                            $("input[name='select_num']:checked").each(function () {
                                stu_nums.push($(this).val());
                            });
                            if (stu_nums.length>0){
                                $.post({
                                    url:"../../requests/teacher/delete_student.php",
                                    data:{'stu_nums':stu_nums,'class_num':class_num},
                                    success:function (data) {
                                        if (data == '1') {
                                            $$.alert('删除成功',function () {
                                                window.location.href="details_stu.html?"+class_num;
                                            });
                                        }
                                        else {
                                            $$.alert('有学生删除失败');
                                            window.location.href="details_stu.html?"+class_num;
                                        }
                                    }
                                });
                                console.log(stu_nums);
                            }
                            else $$.alert('未选中学生');
                        }
                    );

                }
            },
            {
                text:'重置密码',
                onClick:function () {
                    $$.confirm('确认重置密码?',
                        function () {
                            var stu_nums=new Array();
                            $("input[name='select_num']:checked").each(function () {
                                stu_nums.push($(this).val());
                            });
                            if (stu_nums.length>0){
                                $.post({
                                    url:"../../requests/teacher/reset_stu_psw.php",
                                    data:{'stus':stu_nums,'class':class_num},
                                    success:function (data) {
                                        if (data == '1') {
                                            $$.alert('重置成功',function () {
                                                location.reload(true);
                                            });
                                        }
                                        else {
                                            $$.alert('有学生密码重置失败！',function () {
                                                location.reload(true);
                                            });
                                        }
                                    }
                                });
                                console.log(stu_nums);
                            }
                            else $$.alert('未选中学生');
                        }
                    );
                }
            }
        ];
        var button2=[{
            text:'取消',
        }];
        var groups=[button1,button2];
        $$.actions(groups);
    });
}
else window.location.href='../../index.html';
